package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements update supplier the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageUpdateSupp {
	private ConnectionToClient client ;
	private String[] str;
/**
 * Constructor of this class 
 * @param str
 * @param client
 */
	public MessageUpdateSupp(String[] str, ConnectionToClient client) {
		
		this.client= client ;
		this.str= str;
	}
	/**
	 * This method update supplier details in the DB 
	 * @throws SQLException
	 * @throws IOException
	 */
	public void UpdateSupp() throws SQLException, IOException{
		
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement sid = sc.getConnection().prepareStatement("SELECT * FROM db.suppliers where idsuppliers='"+str[1]+"';" );
		ResultSet rss= sid.executeQuery();
		
		 if(rss.next())
			{
			 ArrayList<Object> us=new ArrayList<Object>();
			 us.add("updateSupp");
			 us.add(rss.getInt(1));
			 us.add(rss.getString(2));
			 us.add(rss.getString(3));
			 us.add(rss.getString(4));
			 us.add(rss.getString(5));
			 us.add(rss.getString(6));
		
			 client.sendToClient(us);
			}
	
	
	}
}
